// 在这里可以配置 devproxy 网址，方便灵活选择后台接入点
import { callApi } from './hooks/async';

callApi.getPortalPath = () => 'http://10.39.48.71:8083'; // for dev env

function getSavedToken() {
  const saved = localStorage.getItem('enncloud-accessToken');
  if (saved) return saved;
  return '';
}

// setPortalPathGetter(() => 'http://127.0.0.1:60080'); // for local devproxy
callApi.getExtraHeaders = () => ({
  // Authorization: 'Bearer devproxy-by-LiYong', // 如果需要发 token，发空值，由 devproxy 自动填充；免得前端改token热更新还要等待
  Authorization: `Bearer ${getSavedToken()}`,
});

export const dva = {
  config: {
    onError(err: ErrorEvent) {
      err.preventDefault();
      console.error(err.message);
    },
    extraEnhancers: [],
  },
};
